package com.ls.fw.data.search.impl.lucene.parser;

import java.util.List;

import com.ls.fw.common.beanparser.bean.OrderInfo;
import com.ls.fw.common.beanparser.schema.Order;
import com.ls.fw.common.beanparser.visitor.OrderByVisitor;

public class OrderParser implements OrderByVisitor{

	private StringBuilder sql = new StringBuilder("");
	private boolean first = true;
	private String split = ",";
	
	
	public OrderParser(OrderInfo groupInfo){
		List<Order> list =  groupInfo.getList();
		if(list!=null && list.size()>0){
			sql.append(" ORDER　BY ");
			for (Order order : list) {
				order.accept(this);
			}
		}
	}
	
	public StringBuilder getSql() {
		return sql;
	}

	public void setSql(StringBuilder sql) {
		this.sql = sql;
	}

	@Override
	public void visit(Order order) {
		if(first){
			sql.append(order.getFullName());
		}else{
			sql.append(split+order.getFullName());
		}
		sql.append(" "+order.getOrderType().getName());
		first = false;
	}
}
